<?php
// +----------------------------------------------------------------------
// | 幕小铺
// +----------------------------------------------------------------------
// | 版权所有 2016~2020 幕小铺科技（大连）有限公司
// +----------------------------------------------------------------------
// | 2020/03/14
// +----------------------------------------------------------------------

namespace app\video\model;

use think\Model;
use util\Tree;


/**
 * 视频分类标签 模型
 * @package app\user_center\model
 */
class VideoPlayClassContact extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'xm_video_play_class_contact';
	
    /**
     * 添加数据
     * @param array $list 	标签
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
    public function addData($list){
        $res = $this -> isUpdate(false) -> saveAll($list);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	/**
     * 批量编辑
     * @param pid int 分类id
     * @author shiqiang
     * @return array_out(code, message)
     */
	public function batchEditData($list){
		$res = $this -> saveAll($list);
        if($res !== false){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
    /**
     * 删除数据
     * @param int $id
     * @author shiqiang <976162041@qq.com>
     * @return bool
     */
    public function deleteData($id){
        $res = self::destroy($id);
        if($res){
            return array_out(200, 'success');
        }else{
            return array_out(-1001, 'error');
        }
    }
	
	public function getListByLabelID($pid){
		$map = [];
        $map['pid'] = $pid;
        $list = self::withJoin('getVideoPlayClassLabel', 'LEFT') -> where($map) -> order('id' ,'asc') -> select();
        return array_out(200, 'success', $list);
	}
	
	/**
     * 标签 关联载入（一对一）
     */
    public function getVideoPlayClassLabel(){
        return $this -> hasOne('app\video\model\VideoPlayClassLabel','id','label_id');
    }
}
